<?php
	//includes
	require_once 'includes.php';

	//delete all
//	DB::ExecuteSQL("
//		DELETE FROM t_restaurants;
//	");
	
	$startTime = microtime() + time();
	
	$openTable = new OpenTable();
	$products = $openTable->GetSavedRestaurantURLs($_GET['offset'], $_GET['number']);
//	$urls = $openTable->GetSavedRestaurantURLsByIds($_GET['ids']);
	
	$result = array('success' => 0, 'fail' => 0);
	
	//saves restaurants
	foreach ($products as $url)
	{
		//restaurant item
		$restaurantItem = $openTable->GetRestaurantItem($url['url']);
		
		//URL id
		$restaurantItem->urlId = $url['id'];
		
//		Utils::VarDump($restaurantItem);
		
		//saves the restaurant into DB
		$saveResult = $restaurantItem->Save();
		
		//stats
		if ($saveResult)
		{
			$result['success']++;
		}
		else 
		{
			$result['fail']++;
		}		
	}

	$endTime = microtime() + time();
	
	//totals
	$resultTime = $endTime - $startTime;
	echo "Total time: $resultTime; Success: {$result['success']}; Fail: {$result['fail']}; ";		
	
?>